<template>
  <div class="overlay" @click.self="closePopup">
    <div class="navigation-bar">
      <button class="back-button" @click="backButtonClicked"></button>
      <span class="title">相机设置</span>
      <div class="navigation-bar-seperator"></div>
    </div>
    <div class="content-container">
      <div class="settings-input-item">
        <span>水印id：</span>
        <div class="settings-item-seperator"></div>
        <input
          type="text"
          v-model="viewModel.watermarkId"/><!-- eslint-disable-line vue/no-mutating-props -->
      </div>
      <div class="settings-input-item">
        <span>DeviceModel：</span>
        <div class="settings-item-seperator"></div>
        <input
          type="text"
          v-model="viewModel.deviceModel"/><!-- eslint-disable-line vue/no-mutating-props -->
      </div>
      <div class="settings-input-item">
        <span>水印标题：</span>
        <div class="settings-item-seperator"></div>
        <input
          type="text"
          v-model="viewModel.watermarkTitle"/><!-- eslint-disable-line vue/no-mutating-props -->
      </div>
      <div
        v-for="(item, index) in viewModel.customInputItems"
        :key="index"
        class="settings-input-item"
      >
        <span>{{ item.title }}：</span>
        <div class="settings-item-seperator"></div>
        <input
          type="text"
          v-model="item.value"
        /><!-- eslint-disable-line vue/no-mutating-props -->
      </div>
      <div class="settings-input-item">
        <span>拍照张数：</span>
        <div class="settings-item-seperator"></div>
        <input
          type="text"
          v-model="maxImageCountProxy"/><!-- eslint-disable-line vue/no-mutating-props -->
      </div>

      <div class="settings-input-item">
        <span>水印缩放：</span>
        <div class="settings-item-seperator"></div>
        <input
          type="number"
          v-model="watermarkScale"/>
      </div>

      <div class="settings-switch-item">
        <span>拍照确认：</span>
        <div class="settings-item-seperator"></div>
        <UISwitchComponent class="switch" v-model="disablePhotoConfirmProxy"/>
      </div>
      <div class="settings-switch-item">
        <span>水印选择：</span>
        <div class="settings-item-seperator"></div>
        <UISwitchComponent class="switch" v-model="enableCustomWatermarkProxy"/>
      </div>
      <div class="settings-switch-item">
        <span>移除官方水印：</span>
        <div class="settings-item-seperator"></div>
        <UISwitchComponent class="switch" v-model="disableOffcialWatermarkProxy"/>
      </div>
      <div class="settings-switch-item">
        <span>禁止水印拖拽：</span>
        <div class="settings-item-seperator"></div>
        <UISwitchComponent class="switch" v-model="disableWatermarkDraggingProxy"/>
      </div>

    </div>
  </div>
</template>

<script>
import UISwitchComponent from "./UISwitchComponent.vue";

export default {
  name: "CameraSettingsComponent",
    components: {
        UISwitchComponent,
    },
    computed: {
        disablePhotoConfirmProxy: {
            get() {
                return !this.viewModel.disablePhotoConfirm; // 取反
            },
            set(value) {
                // eslint-disable-next-line vue/no-mutating-props
                this.viewModel.disablePhotoConfirm = !value;
            },
        },
        enableCustomWatermarkProxy: {
            get() {
                return this.viewModel.enableCustomWatermark;
            },
            set(value) {
                // eslint-disable-next-line vue/no-mutating-props
                this.viewModel.enableCustomWatermark = value;
            },
        },
        maxImageCountProxy: {
            get() {
                return this.viewModel.maxImageCount + "";
            },
            set(value) {
                if (value === "") {
                    // eslint-disable-next-line vue/no-mutating-props
                    this.viewModel.maxImageCount = 1;
                    return;
                }
                // eslint-disable-next-line vue/no-mutating-props
                this.viewModel.maxImageCount = parseInt(value);
            },
        },
        watermarkScale: {
          get() {
              return this.viewModel.watermarkScale + "";
          },
          set(value) {
              if (isNaN(value)) {
                  // eslint-disable-next-line vue/no-mutating-props
                  this.viewModel.watermarkScale = 1.0;
                  return;
              }
              // eslint-disable-next-line vue/no-mutating-props
              this.viewModel.watermarkScale = parseFloat(value);
          },
        },
        disableOffcialWatermarkProxy: {
            get() {
                return this.viewModel.disableOffcialWatermark;
            },
            set(value) {
                // eslint-disable-next-line vue/no-mutating-props
                this.viewModel.disableOffcialWatermark = value;
            },
        },
        disableWatermarkDraggingProxy: {
            get() {
                return this.viewModel.disableWatermarkDragging;
            },
            set(value) {
                // eslint-disable-next-line vue/no-mutating-props
                this.viewModel.disableWatermarkDragging = value;
            },
        },
    },
  props: {
    viewModel: Object,
  },
  methods: {
    backButtonClicked() {
      this.$emit("close");
    },
    closePopup() {
      this.$emit("close");
    },
  },
};
</script>

<style scoped>
.overlay {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding: 0px;
  margin: 0px;
}

.navigation-bar {
  width: 100%;
  height: 60px;
  background-color: rgb(237, 237, 237);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  margin: 0px;
  padding: 0px;
}

.navigation-bar-seperator {
  width: 100%;
  height: 1px;
  background-color: #e0e0e0;
  position: absolute;
  bottom: 0;
}

.navigation-bar .title {
  font-size: 18px;
  font-weight: 400;
  color: #333;
}

.navigation-bar .back-button {
  position: absolute;
  left: 16px;
  width: 32px;
  height: 32px;
  background-color: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background-image: url("@/assets/global_border_back_ultrastrong.png");
  background-size: contain;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-touch-callout: none;
  appearance: none;
  -moz-appearance: none;
  -webkit-appearance: none;
}

.content-container {
  width: 100%;
  height: calc(100% - 60px);
  background-color: white;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding: 0px;
  margin: 0px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.settings-input-item {
  width: 100%;
  height: 50px;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  padding: 0px;
  margin: 0px;
  position: relative;
}

.settings-item-seperator {
  width: 100%;
  height: 1px;
  background-color: #f0f0f0;
  position: absolute;
  bottom: 0;
}

.settings-input-item span {
  font-size: 16px;
  font-weight: 400;
  color: #333;
  padding-left: 16px;
}

.settings-input-item input {
  flex: 1;
  margin-right: 16px;
  font-size: 16px;
  height: 40px;
  padding-left: 8px;
  padding-right: 8px;
  border: none;
  background-color: rgb(249, 249, 249);
  border-radius: 4px;
}

.settings-input-item input:focus {
  outline: none;
  border: none;
}

.settings-switch-item {
    width: 100%;
    height: 50px;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    padding: 0px;
    margin: 0px;
    position: relative;
}

.settings-switch-item span {
    font-size: 16px;
    font-weight: 400;
    color: #333;
    padding-left: 16px;
}

.switch {
    margin-left: 8px;
}

</style>
